From 18cbf2503185b4dc58864b524446e8f4502e2cf6 Mon Sep 17 00:00:00 2001 From: Jyrki Gadinger Date: Thu, 17 Apr 2025 18:00:09 +0200 Subject: [PATCH] fix(gui): handle invalid file name edge case on Windows File names like "c:blah" would break the usage of the dialogue, displaying a path like "c://blah" instead. Apparently `QDir::filePath` checks if the passed file name is an absolute file name using `!QFileInfo::isRelative`, which is the case if the second character in the string is a colon -- probably indicating a drive letter. Signed-off-by: Jyrki Gadinger --- src/gui/tray/activitylistmodel.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/gui/tray/activitylistmodel.cpp b/src/gui/tray/activitylistmodel.cpp index b39b354c4..9bd401859 100644 --- a/src/gui/tray/activitylistmodel.cpp +++ b/src/gui/tray/activitylistmodel.cpp @@ -694,8 +694,21 @@ void ActivityListModel::slotTriggerDefaultAction(const int activityIndex) ? InvalidFilenameDialog::InvalidMode::ServerInvalid : InvalidFilenameDialog::InvalidMode::SystemInvalid; +#ifdef Q_OS_WIN + // Edge case time! + // QDir::filePath checks whether the passed `fileName` is absolute (essentialy by using `!QFileInfo::isRelative()`). + // On Windows, if `fileName` starts with a letter followed by a colon (e.g. "A:BCDEF"), it is considered to be an + // absolute path. + // Since the complete desired path is required by InvalidFilenameDialog, catch that special case here and prefix it ourselves... + const auto filePath = activity._file.length() >= 2 && activity._file[1] == ':' + ? folder->path() + activity._file + : folderDir.filePath(activity._file); +#else + const auto filePath = folderDir.filePath(activity._file); +#endif + _currentInvalidFilenameDialog = new InvalidFilenameDialog(_accountState->account(), folder, - folderDir.filePath(activity._file), fileLocation, invalidMode); + filePath, fileLocation, invalidMode); connect(_currentInvalidFilenameDialog, &InvalidFilenameDialog::accepted, folder, [folder]() { folder->scheduleThisFolderSoon(); }); -- 2.30.2